
package com.lee.utils; 
 
import com.lee.logger.Logger; 
 
import java.util.ArrayList; 
import java.util.List; 
 
public  class Combination<T> {
    List<T> itemset;
    int level;
    List<List<T>> combinationList;
 
    public  List<List<T>>  combinations(List<T> itemset, int level){
        this.itemset = itemset;
        this.level = level;
        this.combinationList = new ArrayList<>();
        combination(new ArrayList<>(),this.level,0);
        return combinationList;
    }
    private  void combination(List<T> subItemSet, int n,int start){
 
        if(n>0){
 
            for(int i=start;i<this.itemset.size();i++){
                List<T> tmp = new ArrayList<>(subItemSet);
                tmp.add(this.itemset.get(i));
                combination(tmp,n-1,i+1);
                if(tmp.size() == this.level){
                    this.combinationList.add(tmp);
                };
            }
 
        }
 
    }
} 
